<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .outer {
            width: 300px;
            height: 300px;
            background-color: red;
            margin: 0 auto;
            padding: 50px;
            box-sizing: border-box;
        }

        .center {
            width: 200px;
            height: 200px;
            background-color: pink;
            padding: 50px;
            box-sizing: border-box;
        }

        .inner {
            width: 100px;
            height: 100px;
            /* 设置背景渐变色 线性渐变 to right/bottom to right bottom 径向渐变 */
            background-image: linear-gradient(to right bottom, red, pink, blue);
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="center">
            <div class="inner"></div>
        </div>
    </div>
    <script>
        // 事件冒泡：事件从内向外触发 从最具体的元素（最深的元素）开始触发
        var outer = document.querySelector('.outer');
        var center = document.querySelector('.center');
        var inner = document.querySelector('.inner');
        function handler1() {
            alert('outer执行了')
        }
        function handler2() {
            alert('center执行了')
        }
        function handler3() {
            alert('inner执行了')
        }
        // addEventListener 第三个参数 false-->事件在冒泡阶段执行 事件从内向外触发
        // outer.addEventListener('click',handler1,false);
        // center.addEventListener('click',handler2,false);
        // inner.addEventListener('click',handler3,false);

        // true --->事件在捕获阶段执行 事件从外向内触发
        outer.addEventListener('click', handler1, true);
        center.addEventListener('click', handler2, true);
        inner.addEventListener('click', handler3, true);
    </script>
</body>

</html> 